package com.bluedot.dao;

import java.util.List;
import com.bluedot.dao.CustDao;
import org.hibernate.Query;
import org.hibernate.Session;

import com.bluedot.domain.Cust;

public class CustDaoImpl extends HibernateDaoSupport<Cust, Long> implements
CustDao {
	public CustDaoImpl() {
		this.entityClass = Cust.class;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Cust> findAllCust() {
		Session session = null;
		List<Cust> list = null;
		try {
			session = this.getSession();
			session.beginTransaction().begin();
			Query query = session.createQuery("from Cust order by cust_id");
			list = query.list();
			session.getTransaction().commit();
		} catch (RuntimeException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		return list;
	}

	public void saveCust(Cust cust) {
		Session session = null;
		try {
			session = this.getSession();
			session.beginTransaction().begin();
			session.save(cust);
			session.getTransaction().commit();
		} catch (RuntimeException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}

	}


	// @Override
	// public void create(Cust entity) {
	//	
	//
	// }
	//
	// @Override
	// public void delete(Cust entity) {
	//
	//
	// }
	//
	// @Override
	// public Cust findById(Long id) {
	// //
	// return null;
	// }
	//
	// @Override
	// public void saveOrUpdate(Cust cust) {
	//
	// Session session = null;
	// try {
	// session = this.getSession();
	// session.beginTransaction().begin();
	// session.save(cust);
	// session.getTransaction().commit();
	// } catch (RuntimeException e) {
	// e.printStackTrace();
	// } finally {
	// session.close();
	// }
	//
	// }
	//
	// @Override
	// public void update(Cust entity) {
	// //
	//
	// }

}
